package com.dailyblue.java.spring.consumer.handler;

import com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.BlockExceptionHandler;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.dailyblue.cloud.bookstore.commons.util.JsonResult;
import com.dailyblue.cloud.bookstore.commons.util.ResultCode;
import com.dailyblue.cloud.bookstore.commons.util.ResultTool;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;

@Component
public class FirstHandler implements BlockExceptionHandler {
    @Override
    public void handle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, BlockException e) throws Exception {
        PrintWriter out = httpServletResponse.getWriter();
        out.println(ResultTool.fail(ResultCode.COMMON_FAIL));
    }
}
